﻿using System;
using System.IO; 

/*
本质就是字符串拼接的操作
*/
class Program
{
    static void Main(string[] args)
    {
        string relativePath = @"\新建文本文档.txt";
        string path = @"D:\My\.Net Project\文件操作\Path类操作\新建文本文档.txt";
        string path1 = @"D:\My";
        string path2 = ".Net Project";
        string path3 = "文件操作";
        string path4 = "Path类操作";

        /*基础操作*/
        //Combine(path1, path2,path3,path4);
        //GetExtension(path);
        //GetFileName(path);
        //GetFileNameWithoutExtension(path);
        //GetFullPath(relativePath);

        Console.ReadKey();
    }
    /// <summary>
    /// 将字符串组合变成路径
    /// </summary>
    /// <param name="paths"></param>
    static void Combine(params string[] paths)
    {
        string newPath = Path.Combine(paths);
        Console.WriteLine(newPath);
    }
    /// <summary>
    /// 获取指定路径文件的扩展名
    /// </summary>
    static void GetExtension(string path)
    {
        Console.WriteLine(Path.GetExtension(path));
    }
    /// <summary>
    /// 根据路径指定位置获取文件名
    /// </summary>
    /// <param name="path"></param>
    static void GetFileName(string path)
    {
        Console.WriteLine(Path.GetFileName(path));
    }
    /// <summary>
    /// 根据路径指定位置获取文件名,不包含扩展名
    /// </summary>
    static void GetFileNameWithoutExtension(string path)
    {
        Console.WriteLine(Path.GetFileNameWithoutExtension(path));
    }
    /// <summary>
    /// 通过相对路径获取文件的全部路径
    /// (用于创建新文件,将此路径传递作为新文件路径)
    /// </summary>
    static void GetFullPath(string path)
    {                                      //工作目录+传递过来的文件名 = 文件的路径
        Console.WriteLine(Path.GetFullPath(Directory.GetCurrentDirectory()+path));
    }
}